//39.组合总和 https://leetcode-cn.com/problems/combination-sum/
class Solution {
public:
    void backtracking(vector<int>&candidates,int target,int startindex,int count)
    {
        if(count == target)
        {
            result.push_back(temp);
            return;
        }
        if(count > target)
            return;
        for(int i = startindex;i < candidates.size();i++)
        {
            temp.push_back(candidates[i]);
            count+=candidates[i];
            backtracking(candidates,target,i,count);
            count-=candidates[i];
            temp.pop_back();
        }
    }
    vector<int> temp;
    vector<vector<int>> result;
    vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
        backtracking(candidates,target,0,0);
        return result;
    }
};